 /* 
 * File:   cSentinelNest.cpp
 * Author: josep
 * 
 * Created on 27 / desembre / 2010, 15:22
 */

#include "cSentinelNest.h"

int counter=0;

cSentinelNest::cSentinelNest(){
    srand(time(NULL));
    nextTime=0;
    currentTime=0;
    getTheNextTime();
}

cSentinelNest::cSentinelNest(const cSentinelNest& orig):cAgentNest(orig) {
    Camera=orig.Camera;
    Data = orig.Data;
    nextTime=orig.nextTime;
}

void cSentinelNest::SetCamera(cCamera* Camera) {
    this->Camera = Camera;
}
void cSentinelNest::SetData(cData* Data) {
    this->Data = Data;
}

cSentinelNest::~cSentinelNest() {
}

void cSentinelNest::NextStep(int time){

    currentTime+=time;
    if(nextTime<=currentTime){
        int x, y;
        //generar
        if(Camera->GetDirectionX()>=0){
            //apareceran por la derecha
            x=Camera->GetPosX()+Camera->GetWidth()+(Camera->GetSpeedX()*2);
            y=300;
        }else{
            //apareceran por la izquierda
            x=Camera->GetPosX()-(Camera->GetSpeedX()*2);
            y=300;
        }
        cSentinel* ag = new cSentinel();
        ag->InitFromIniFile(SENTINEL_CFG, Data, x ,y );
        /*
        ag->SetSurfaceType(NORTH_SURFACE, SOFT_SURFACE);
        ag->SetSurfaceType(EAST_SURFACE, NORMAL_SURFACE);
        ag->SetSurfaceType(WEST_SURFACE, NORMAL_SURFACE);
        ag->SetSurfaceType(SOUTH_SURFACE, NORMAL_SURFACE);
         */
        /**/
        ag->SetSurfaceType(NORTH_SURFACE, SOFT_SURFACE);
        ag->SetSurfaceType(EAST_SURFACE, HARD_SURFACE);
        ag->SetSurfaceType(WEST_SURFACE, HARD_SURFACE);
        ag->SetSurfaceType(SOUTH_SURFACE, HARD_SURFACE);
         /**/
        ag->SetNom("Sentinel");
        children.push((cAutonomousAgent*)ag);

        nextTime=currentTime;
        getTheNextTime();
    }
}

void cSentinelNest::getTheNextTime(){
    int t = rand();
    t=(t%(MAX_TIME_PER_BIRTH-MIN_TIME_PER_BIRTH) + MIN_TIME_PER_BIRTH);
    nextTime+=t;
}


